using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using WiMo.Games.Audio;

namespace WiMo.Games.GameEngine.WP7S.XNA
{
    public class ContentManager : IContentManager
    {
        private Microsoft.Xna.Framework.Content.ContentManager _contentManager;

        public ContentManager(IGameEngine engine, Microsoft.Xna.Framework.Content.ContentManager contentManager)
        {
            AssetFactory = engine.AssetFactory;
            Engine = engine;
            _contentManager = contentManager;
        }

        private ContentManager() { }

        public IAssetFactory AssetFactory { get; private set; }
        public IGameEngine Engine { get; set; }

        public string ContentLocation
        {
            get{return _contentManager.RootDirectory;}
            set{_contentManager.RootDirectory = value;}
        }

        public WiMo.Games.Audio.IGameAudio LoadAudio(string name)
        {
            IGameAudio gameAudio = AssetFactory.CreateAudioInstance();
            gameAudio.AudioInformation = _contentManager.Load<SoundEffect>(name);

            return gameAudio;
        }

        public WiMo.Games.Drawables.ISpriteImage LoadImage(string name)
        {
            var spriteImage = AssetFactory.CreateSpriteImage();
            try
            {
                spriteImage.Load(Engine.ContentManager, @"WP7/" + name);
            }
            catch (Exception exc)
            {
                spriteImage.Load(Engine.ContentManager, name);
            }
            return spriteImage;
        }

        public WiMo.Games.Drawables.ITexture GetTexture(string name)
        {
            var texture = new Drawables.Texture();
            texture.TextureInformation = _contentManager.Load<Texture2D>(name);
            return texture;
        }

        public string GetFullPath(string name)
        {
            throw new NotImplementedException();
        }

        public ISpriteFont GetFont(string name)
        {
            var font = AssetFactory.CreateFont();
            font.FontInformation = _contentManager.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>(name);

            return font;
        }

        public void Dispose()
        { 

        }

    }
}